<?php
// 初始化棋盘
$board = [
    ['象', '狮', '虎', '豹', '狼', '狗', '猫', '鼠'],
    array_fill(0, 8, null),
    array_fill(0, 8, null),
    array_fill(0, 8, null),
    array_fill(0, 8, null),
    array_fill(0, 8, null),
    array_fill(0, 8, null),
    ['鼠', '猫', '狗', '狼', '豹', '虎', '狮', '象']
];

// 处理移动逻辑（简单示例，未完善所有规则）
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $fromX = $_POST['fromX'];
    $fromY = $_POST['fromY'];
    $toX = $_POST['toX'];
    $toY = $_POST['toY'];

    $piece = $board[$fromY][$fromX];
    $target = $board[$toY][$toX];

    // 简单的移动逻辑，不考虑规则细节
    if ($piece && (!$target || $target)) {
        $board[$toY][$toX] = $piece;
        $board[$fromY][$fromX] = null;
    }
}
?>

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网页版斗兽棋游戏</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <h1>网页版斗兽棋游戏</h1>
    <div id="board">
        <?php
        for ($y = 0; $y < 8; $y++) {
            for ($x = 0; $x < 8; $x++) {
                $piece = $board[$y][$x];
                $cellClass = $piece ? 'piece' : 'empty';
                echo "<div class='cell $cellClass' data-x='$x' data-y='$y'>";
                if ($piece) {
                    echo $piece;
                }
                echo "</div>";
            }
        }
        ?>
    </div>
    <form id="moveForm" method="post">
        <input type="hidden" id="fromX" name="fromX">
        <input type="hidden" id="fromY" name="fromY">
        <input type="hidden" id="toX" name="toX">
        <input type="hidden" id="toY" name="toY">
    </form>
    <script src="script.js"></script>
</body>

</html>